package com.zpl.entity;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author wangyuxin
 * @date 2020/9/28
 */
public class BaseEnumSerializer extends JsonSerializer<BaseEnum> {

    /**
     * 构建序列化数据
     * @param value
     * @param gen
     * @param serializers
     * @throws IOException
     */
    @Override
    public void serialize(BaseEnum value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        Map<String,Object> map = new HashMap<>();
        map.put("name", value.getName());
        map.put("code", value.getCode());
        map.put("displayName", value.getDisplayName());
        gen.writeObject(map);
    }
}
